package com.xxxy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxxy.commonResult.CommonResultPage;
import com.xxxy.dao.QuestionDao;
import com.xxxy.model.KnowledgePoint;
import com.xxxy.model.Question;
import com.xxxy.response.QuestionDetailResponse;
import com.xxxy.response.QuestionResponse;
import com.xxxy.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author sjh
 * @date 2022/2/26 14:53
 */
@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionDao, Question> implements QuestionService {

    @Autowired
    QuestionDao questionDao;

    @Override
    public CommonResultPage listQuestion(Integer page, Integer size, Integer type, KnowledgePoint knowledgePoint) {
        PageHelper.startPage(page,size);
        List<QuestionResponse> questionList = questionDao.list(type, knowledgePoint);
        PageInfo<QuestionResponse> pageInfo = new PageInfo<>(questionList);
        CommonResultPage result = new CommonResultPage();
        result.setTotal(pageInfo.getTotal());
        result.setData(pageInfo.getList());
        return result;
    }

    @Override
    public QuestionDetailResponse getQuestionById(Integer questionId) {
        QuestionDetailResponse questionDetailResponse = questionDao.getQuestionById(questionId);
        if(questionDetailResponse != null){
            return questionDetailResponse;
        }
        return null;
    }
}
